﻿using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace AnalyStock.DataManage;

[Table("Daily")]
public class Daily //12 fields
{
    public string Ts_code { get; set; }
    [Key] public string Trade_date { get; set; }
    public float Open { get; set; }
    public float High { get; set; }
    public float Close { get; set; }
    public float Low { get; set; }
    public float Pre_close { get; set; }
    public float Change { get; set; }
    public float Pct_chg { get; set; }
    public float Vol { get; set; }
    public float Amount { get; set; }
    public float Adj_factor { get; set; }

    public override bool Equals(object obj)
    {
        if (obj is not Daily inforObj)
        {
            return false;
        }

        if (Trade_date == inforObj.Trade_date && Ts_code == inforObj.Ts_code)
        {
            return true;
        }

        return false;
    }

    public override int GetHashCode()
    {
        return ($"{Trade_date}{Ts_code}").GetHashCode();
    }
}

public class AdjFactor
{
    public string Ts_code { get; set; }
    [Key] public string Trade_date { get; set; }
    public float Adj_factor { get; set; }
}

public class TradeCalendar
{
    public string Exchange { get; set; }
    public string Cal_date { get; set; }
    public string Is_open { get; set; }
    public string Pretrade_date { get; set; }
}

[Table("StockBasic")]
public class StockBasic //7 fields
{
    [Key] public string Ts_code { get; set; }
    public string Symbol { get; set; }
    public string Name { get; set; }
    public string Cnspell { get; set; }
    public string Area { get; set; }
    public string Industry { get; set; }
    public string Market { get; set; }
    public string Exchange { get; set; }
    public string List_date { get; set; }
    public string Delist_date { get; set; }
}

[Table("BakDaily")]
public class BakDaily //26 fields
{
    [Key] public string Ts_code { get; set; }
    public string Name { get; set; }
    public string Trade_date { get; set; }
    public float Pct_change { get; set; }
    public float Close { get; set; }
    public float Change { get; set; }
    public float Open { get; set; }
    public float High { get; set; }
    public float Low { get; set; }
    public float Pre_close { get; set; }
    public float Vol_ratio { get; set; }
    public float Turn_over { get; set; }
    public float Swing { get; set; }
    public float Vol { get; set; }
    public float Amount { get; set; }
    public float Selling { get; set; }
    public float Buying { get; set; }
    public float Total_share { get; set; }
    public float Float_share { get; set; }
    public float Pe { get; set; }
    public float Float_mv { get; set; }
    public float Total_mv { get; set; }
    public float Strength { get; set; }
    public float Activity { get; set; }
    public float Avg_turnover { get; set; }
    public float Attack { get; set; }
}

[Table("SelectStock")]
public class SelectStock
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int Id { get; set; }
    public string Ts_code { get; set; }
    public string Name { get; set; }
    public string Industry { get; set; }
    public string Conception { get; set; }
    public string SelfType { get; set; }   
    public string OrderID { get; set; }
}

[Table("Conception")]
public class Conception
{
    public Conception() { }
    public Conception(string id, string name, string orderID)
    {
        ID = id;
        Name = name;
        OrderID = orderID;
    }

    [Key] public string ID { get; set; }
    public string Name { get; set; }
    public string OrderID { get; set; }
    
}
[Table("StockNote")]
public class StockNote
{   
    [Key] public string Ts_code { get; set; }
    public string Name { get; set; }
    public string Note { get; set; }
}

[Table("DynamicFinancialIndex")]
public class DynamicFinancialIndex
{
    //[Display(Name = "股票代码")] 
    public string Ts_code { get; set; }
    //[Display(Name = "公告日期")] 
    public string Ann_date { get; set; }
    [Key] public string End_date { get; set; }
    public float Eps { get; set; }
    public float Q_eps { get; set; }
    public float Bps { get; set; }
    //BPS=Book value Per Share，每股帐面价值，也称每股净资产的意思，有时候也会称为Net assets per share。
    public float Ocfps { get; set; }
    public float Or_yoy { get; set; }
    public float Op_yoy { get; set; }
    public float Ocf_yoy { get; set; }
    public float Q_sales_qoq { get; set; }
    public float Q_op_qoq { get; set; }
    public float Netprofit_margin { get; set; }
    public float Grossprofit_margin { get; set; }
    public float Roe { get; set; }
    public float Debt_to_assets { get; set; }
    public float Gross_margin { get; set; }
    public float Extra_item { get; set; }
    public float Non_op_profit { get; set; }
    public float Profit_dedt { get; set; }


    public override bool Equals(object obj)
    {
        if (obj is not DynamicFinancialIndex finanObj)
        {
            return false;
        }

        if (End_date == finanObj.End_date && Ts_code == finanObj.Ts_code)
        {
            return true;
        }
        return false;
    }

    public override int GetHashCode()
    {
        return ($"{End_date}{Ts_code}").GetHashCode();
    }

    public static string[] GetPropertyChineseName()
    {
        //return typeof(FinancialIndex).GetProperties()
        //      .Select(p => p.GetCustomAttribute<DisplayAttribute>().Name).ToArray();       
        return
        [
            "01报告期",
            "02基本每股收益",
            "03每股收益/单季",
            "04每股净资产",
            "05每股经营净现金",
            "06营业收入-同比",
            "07营业利润-同比",
            "08经营净现金-同比",
            "09营业收入-环比",
            "10营业利润-环比",
            "11销售净利率",
            "12销售毛利率",
            "13净资产收益率",
            "14资产负债率",
            "15毛利/万元",
            "16非经常性损益/万元",
            "17非营业利润/万元",
            "18扣非净利润/万元",
        ];
    }


    public string[] GetPropertyValues()
    {
        // return GetType().GetRuntimeProperties()
        //                 .Select(n => n.GetValue(this)).Skip(2).ToArray();
        return
       [
            $"{End_date}",
            $"{Eps:F2}",
            $"{Q_eps:F2}",
            $"{Bps:F2}",
            $"{Ocfps:F2}",
            $"{Or_yoy:F1}%",
            $"{Op_yoy:F1}%",
            $"{Ocf_yoy:F1}%",
            $"{Q_sales_qoq:F1}%",
            $"{Q_op_qoq:F1}%",
            $"{Netprofit_margin:F1}%",
            $"{Grossprofit_margin:F1}%",
            $"{Roe:F1}%",
            $"{Debt_to_assets:F1}%",
            $"{Gross_margin/10000:F0}",
            $"{Extra_item/10000:F0}",
            $"{Non_op_profit/10000:F0}",
            $"{Profit_dedt/10000:F0}",
       ];

    }
}
public class StockInfo //30 fields 看板
{
    public string Ts_code { get; set; } //1   
    public string Name { get; set; } //2
    public string Area { get; set; } //13        
    public string Industry { get; set; } //14 
    public string Conception { get; set; }
    public string Market { get; set; } //15    
    public float Pe { get; set; } //6       
    public float Total_mv { get; set; } //10
    public float Float_mv { get; set; } //9 
    public float Total_share { get; set; } //11       
    public float Float_share { get; set; } //12   
    public bool IsSele { get; set; }  //是否自选股
    public float Vol_ratio { get; set; }
    public float Turn_over { get; set; }
    public string Trade_date { get; set; }
    public string Note { get; set; }

    public string[] TextPropertyVal() //列示
    {
        return
        [
            "股票代码: " + Ts_code,
            "股票名称: " + Name,
            "地   区: " + Area,
            "所属行业: " + Industry,
            "概念分类: " + Conception,
            "所属市场: " + Market,
            "动态市盈率: " + Pe,
            "总市值/亿元: " + Total_mv,
            "流通市值/亿元: " + Float_mv,
            "总股数/亿股: " + Total_share,
            "流通股数/亿股: " + Float_share,
            "备份日期:" + Trade_date,
            "量  比:\t" + Vol_ratio,
            "换手率:\t" + Turn_over
        ];
    }

    public object[] GetPropertyValues()
    {
        return
        [
            Ts_code, Name, Area, Industry, Conception, Market,
            Pe, Total_mv, Float_mv, Total_share, Float_share,
            Trade_date, Vol_ratio, Turn_over, Note
        ];
    }
}


//分钟数据
public class MinuteData
{
    public string Ts_code { get; set; }
    public string Date { get; set; }
    public string Mintue { get; set; }
    public float Price_timely { get; set; }
    public float Price_mean { get; set; }
    public float Volume { get; set; }
    public float Yestclose { get; set; }
}

/// <summary>
/// 腾讯日线数据结构
/// </summary>
public class DailyOfTencent
{
    public string Name { get; set; }
    public string Stockcode { get; set; }
    public string Date { get; set; }
    public float Open { get; set; }
    public float High { get; set; }
    public float Close { get; set; }
    public float Low { get; set; }
    public float YestClose { get; set; }
    public float Change { get; set; }
    public float Pct_chg { get; set; }
    public float Vol
    {
        get => Stockcode[..2] == "68" ? (int)_vol / 100 : _vol;
        set => _vol = value;
    }    
    private float _vol;
    public float Amount { get; set; }
    public float Turn_over { get; set; }
    public float PE { get; set; }
    public object[] GetPropertyValues()
    {
        return
        [
            Name,Open, Close, Pct_chg, Turn_over, PE, Vol
        ];
    }
}
/// <summary>
/// 腾讯分钟线原始格式
/// </summary>
public class MinuteOfTencent
{
    [JsonPropertyName("data")] public string[] Data { get; set; }
    [JsonPropertyName("date")] public string Date { get; set; }
}

